import React, { Component } from "react";
import PropTypes from "prop-types";
export const connect = function(mapToState, mapToDispatch) {
  return function(WarpperPage) {
    class newPage extends WarpperPage {
      constructor(props, context) {
        super(props, context);
        this.store = props.store || context;
        console.log("store", this.store, "context", context);
      }
      shouldComponentUpdate(nextProps, nextState) {
        console.log("props更新", this.props, nextProps);
        return true;
      }
      componentWillReceiveProps(nextProps) {
        console.log("connect recieve props", nextProps);
      }

      render() {
        const nextStroe = mapToState(this.store);
        return <WarpperPage {...nextStroe} />;
      }
    }
    // 子组件接收整个store
    newPage.contextTypes = {
      store: PropTypes.object
    };
    return newPage;
  };
};
